package com.example.testanimation.graphics.matrix.color;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ColorMatrix;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
import com.example.testanimation.R;
import com.lenovo.nova.util.BaseActivity;

/**
 * Created by scenic on 2015/3/28.
 */
public class ColorMatrixTestActivity extends BaseActivity{

    private Bitmap mBitmap;
    private ImageView imageView2;

    private int MAX= 255;
    private int MID = 127;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_matrix_color_image_test);
        mBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.jpg_test);

        imageView2 = (ImageView)findViewById(R.id.imageView2);
        SeekBar seekBar1 = (SeekBar) findViewById(R.id.seekBar);
        SeekBar seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
        SeekBar seekBar3 = (SeekBar) findViewById(R.id.seekBar3);
        seekBar1.setOnSeekBarChangeListener(listener);
        seekBar2.setOnSeekBarChangeListener(listener);
        seekBar3.setOnSeekBarChangeListener(listener);

        doCommon(seekBar1);
        doCommon(seekBar2);
        doCommon(seekBar3);
    }

    private void doCommon(SeekBar seekBar){
        seekBar.setMax(MAX);
        seekBar.setProgress(MID);

    }
    float hue = 0;
    float saturation = 0;
    float lum = 0;
    private SeekBar.OnSeekBarChangeListener listener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
            Bitmap bm;


            switch (seekBar.getId()){
                case R.id.seekBar:
                    hue = (progress - MID) * 1.0f /MID * 180;
                    break;
                case R.id.seekBar2:
                    saturation = progress * 1.0f / MID;
                    break;
                case R.id.seekBar3:
                    lum = progress * 1.0f / MID;
                    break;


            }

//            bm = ImageColorUtils.handlerImageEffect(mBitmap, hue, saturation, lum);
//            imageView2.setImageBitmap(bm);

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    };

    public void test(){
        ColorMatrix hueMatrix = new ColorMatrix();
        //色调
//        hueMatrix.setRotate(0,hue);
//        hueMatrix.setRotate(1,hue);
//        hueMatrix.setRotate(2,hue);

//        饱和度
//        hueMatrix.setSaturation(saturation);

        //调度
//        hueMatrix.setScale(lum,lum,lum,1);
    }
}
